import axios from 'axios';
import { DataCenterAPI } from '@/consts';

export const magicAPI = (payload) => {
    const { method, baseAPI, action, data, } = payload;

    const apiPrefix = baseAPI || DataCenterAPI;
    const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyLXlySFVtME5pYjRqbkRXNzA3MCtUTm0xdExjZ3pNXC83UVVcL2pmUVdOZTg5WFJMOEpiZW9CNmhEMXpESUxxM2dmdm1iZndod3VmeUhkYVBsRTh1akZwTVhvSmdPOXpONEk2OFNmNzlnM3daUT09IiwidWlkIjoiNjE2ZDQ2MWJlNTU0MjI2ZmIyYjgyNmMzIiwic3JjIjoiYW1pbmVyIiwicm9sZXMiOlsicm9zdGVyX2VkaXRvciIsImRhX2Fubm90YXRvciJdLCJpc3MiOiJhcGkuYW1pbmVyLm9yZyIsImV4cCI6MTY1MjQyOTg1OSwiaWF0IjoxNjQ5ODM3ODU5LCJqdGkiOiI2NDU4ZWRhOWE2MzMxZjc0YWVhZjQ2ZjIzMDIyZjhkYTMxMzUxZjgyMDFjZmE3MGQxMWNiOWQ5ZGE1ZDgzMzgzOTc4MWRhMWIyYjExOGYyNDE2Y2UxODUxMjY2YmQxYWU0ZWFlYjExN2U4NWMxNDljNzIxNDhiZGNkYjIzZDUyYmYxZjNiMmIxMWY0M2M1NmEwYzA1NWQ2Mjc2YjNlODhkNzE4NmVkNzY3ZTUyMTY0MTYzYzI1MmRlODgwMDQxMDUzNzU5MDY5NGFkZTJlMTNjMjgzYzBlNTk3YzM3NGZlYjZiNmMwOTMyMWZmOTdhM2NiYjRhMDY5Zjc2MmEzMDUxIiwiZW1haWwiOiJ5aS56aGFuZ0BhbWluZXIuY24ifQ.NTcAW5q-57fFHpp4U5AaSpIGbJFeoGnvGHQMqiEDQfc';
    const options = {
        method: method || 'post',
        url: `${apiPrefix}/magic?a=${action}`,
        data: [{
            action,
            parameters: data,
        }],
        headers: {
            Authorization: token,
        }
    };
    return axios(options);
};